package cn.topevery.garden.wapi.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.topevery.garden.dal.logic.ProjBasicInfoLogic;
import cn.topevery.garden.entity.dto.ProjBasicInfoDTO;
import cn.topevery.garden.entity.po.ProjBasicInfo;
import cn.topevery.garden.entity.query.ProjBasicInfoQuery;
import cn.topevery.garden.entity.vo.ProjBasicInfoAndFilesVO;
import cn.topevery.garden.entity.vo.ProjBasicInfoVO;
import cn.topevery.garden.entity.vo.ProjDetailVO;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.UUID;

/**
 * 项目基本信息表
 *
 * @Author LiBo
 * @Date 2022/11/2 15:17
 */
@Api(tags = "工程项目-项目基本信息表")
@RestController
@RequestMapping("/projBasicInfo")
public class ProjBasicInfoController extends BaseController {

    @Autowired
    ProjBasicInfoLogic projBasicInfoLogic;

    /**
     * 新增/编辑 信息
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增/编辑 信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody ProjBasicInfoDTO dto) {
        if (ObjectUtil.isEmpty(dto.getId())) {
            dto.setProjId(UUID.randomUUID().toString());
        }
        projBasicInfoLogic.saveOrUpdate(getUser().userId, dto);
        return JsonResult.ok(true);
    }

    /**
     * 获取项目基本信息表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取项目基本信息表页列表")
    @PostMapping("/listPage")
    public JsonResult<DataPager<ProjBasicInfoVO>> listPage(@RequestBody ProjBasicInfoQuery query) {
        return JsonResult.ok(projBasicInfoLogic.listPage(query));
    }

    /**
     * 根据id获取详情
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取详情")
    @GetMapping("/getById")
    public JsonResult<ProjBasicInfoAndFilesVO> getById(@RequestParam(value = "id") Integer id) {
        return JsonResult.ok(projBasicInfoLogic.getBasicInfoVOById(id));
    }

    @ApiOperation("首页-根据id获取项目计划、给付情况")
    @GetMapping("/index/getDetailById")
    public JsonResult<ProjDetailVO> getIndexDetailById(@RequestParam(value = "id") Integer id) {
        return JsonResult.ok(projBasicInfoLogic.getProjDetailById(id));
    }
    /**
     * 根据自增ID批量删除
     *
     * @param dto
     * @return
     */
    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody ProjBasicInfoDTO dto) {
        projBasicInfoLogic.delete(getUser().userId, dto.getIds());
        return JsonResult.ok(true);
    }

//    @ApiOperation("导出项目基本信息表信息")
//    @GetMapping("/export")
//    public void export(ProjBasicInfoQuery query, HttpServletResponse response) {
//        List<ProjBasicInfoVO> list = projBasicInfoLogic.listPage(query).records;
//        ExcelUtil.exportExcel(list, "项目基本信息表", "sheet1", ProjBasicInfoVO.class, "项目基本信息表", response);
//    }
}
